// pages/goldenPig/goldenPig.js 
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: { 
    hbinfo:"",
    money:0.00,
    five:0,
    list:[],
    interval:0,
    scrollInfo: 'scroll_rowA',
    goldenPig1: [
      { url: 'https://www.mojingkj.cn/static/images/goldenPig1.png', logo: '/img/wlogo.png', name: '魔睛智能名片', text: '人寿年丰\n福满财满' },
      { url: 'https://www.mojingkj.cn/static/images/goldenPig1.png', logo: '/img/wlogo.png', name: '魔睛智能名片', text: '人寿年丰\n福满财满' },
    ],
    goldenPig2: [
      { url: 'https://www.mojingkj.cn/static/images/goldenPig2.png', logo: '/img/wlogo.png', name: '魔睛智能名片', text: '人寿年丰\n福满财满' },
    ],
    goldenPig3: [],
    goldenPig4: [],
    goldenPig5: [
      { url: 'https://www.mojingkj.cn/static/images/goldenPig5.png', logo: '/img/wlogo.png', name: '魔睛智能名片', text: '人寿年丰\n福满财满' },
    ],
    rule: false,
    animationData1: {},

    animationCard1: {},
    animationCard2: {},
    animationCard3: {},
    animationCard4: {},
    animationCard5: {},

    animationCompound1: {},
    animationShadow1: {},
    animationShadow2: {},
    packetPopup: true,
    open: false,  //当前是否拆
  },
  dotHandle: function (e) {
    let that = this
    let scrollInfoNew = 'scroll_row' + e.currentTarget.dataset.tips
    that.setData({
      scrollInfo: scrollInfoNew
    }) 
  },
  ruleHandle: function (e) {
    let that = this
    that.setData({
      rule: !that.data.rule
    })
  },
  // 卡片合成
  compoundHandle: function (e) {
    var that = this;
    if(that.data.five == 0){
      wx.showToast({
        title: '您还没有集齐哦',
        icon:"none"
      })
      return;
    }
    wx.showLoading({
      title: '',
    })
    wx.request({
      url: app.siteinfo.rootpath+'overcard',
      method:"get",
      data:{uid:app.siteinfo.userinfo.id},
      success:function(res){
        wx.hideLoading()
        if(res.data.code == 500){
          wx.showToast({
            title: '合成失败',
            icon:"none"
          })
          return;
        } if (res.data.code == 203) {
          wx.showToast({
            title: '已有合成卡片',
            icon: "none"
          })
          return;
        }else{
          that.setData({
            money:res.data.money
          })

        
    var animationShadow = wx.createAnimation({ duration: 500, timingFunction: 'linear' })
          that.animationShadow = animationShadow
          that.animationShadow.opacity(1).step()
          that.setData({
            animationShadow1: that.animationShadow.export(),
    })
    var n = 0;
    //连续动画需要添加定时器,所传参数每次+1就行
    var shadowInterval = setInterval(function () {
      n = n + 1;
      console.log(n);
      that.animationShadow.rotate(360 * (n)).step()
      that.setData({
        animationShadow1: that.animationShadow.export()
      })
    }.bind(that), 500)
    setInterval(function () {
      clearInterval(shadowInterval)
      that.animationShadow.opacity(0).step()
      that.setData({
        animationShadow1: that.animationShadow.export(),
        packetPopup: false
      })
    }.bind(that), 1000)

    var animationcard1 = wx.createAnimation({ duration: 800, timingFunction: 'ease', })
          that.animationcard1 = animationcard1
          that.animationcard1.bottom('656rpx').left('328rpx').step()
          that.animationcard1.bottom('396rpx').step()
          that.animationcard1.opacity(0).step()

    var animationcard2 = wx.createAnimation({ duration: 800, timingFunction: 'ease' })
          that.animationcard2 = animationcard2
          that.animationcard2.bottom('448rpx').left('60rpx').step()
          that.animationcard2.bottom('396rpx').left('328rpx').step()
          that.animationcard2.opacity(0).step()

    var animationcard3 = wx.createAnimation({ duration: 800, timingFunction: 'ease' })
          that.animationcard3 = animationcard3
          that.animationcard3.bottom('448rpx').left('590rpx').step()
          that.animationcard3.bottom('396rpx').left('328rpx').step()
          that.animationcard3.opacity(0).step()

    var animationcard4 = wx.createAnimation({ duration: 800, timingFunction: 'ease' })
          that.animationcard4 = animationcard4
          that.animationcard4.bottom('188rpx').left('160rpx').step()
          that.animationcard4.bottom('396rpx').left('328rpx').step()
          that.animationcard4.opacity(0).step()

    var animationcard5 = wx.createAnimation({ duration: 800, timingFunction: 'ease' })
          that.animationcard5 = animationcard5
          that.animationcard5.bottom('188rpx').left('490rpx').step()
          that.animationcard5.bottom('396rpx').left('328rpx').step()
          that.animationcard5.opacity(0).step()

    var animationCompound1 = wx.createAnimation({ duration: 800, timingFunction: 'ease', delay: 1200 })
          that.animationCompound1 = animationCompound1
          that.animationCompound1.opacity(0).step()

    var animationData1 = wx.createAnimation({ duration: 500, timingFunction: 'ease', delay: 600 })
          that.animationData1 = animationData1
          that.animationData1.opacity(0).step()

    var animationFireworks = wx.createAnimation({ duration: 500, timingFunction: 'ease', delay: 1300 })
          that.animationFireworks = animationFireworks
          that.animationFireworks.opacity(1).step()

    var animationOpacity = wx.createAnimation({ duration: 500, timingFunction: 'ease', delay: 1200 })
          that.animationOpacity = animationOpacity
          that.animationOpacity.opacity(0).step()

    that.setData({
      animationCard1: animationcard1.export(),
      animationCard2: animationcard2.export(),
      animationCard3: animationcard3.export(),
      animationCard4: animationcard4.export(),
      animationCard5: animationcard5.export(),
      animationCompound1: animationCompound1.export(),
      animationData1: animationData1.export(),
      animationFireworks: animationFireworks.export(),
      animationOpacity: animationOpacity.export(),
    })
        }
      }
    })
    
  },

  openHandle: function () {
    let that = this
    // 还没到开奖时间
    // wx.showToast({
    //   title: '还没到开奖时间哦',
    //   icon: 'none',
    //   duration: 2000
    // })
    // 到开奖时间
    that.setData({
      open: true
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成 
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: app.siteinfo.rootpath+'mypig',
      data:{uid:app.siteinfo.userinfo.id},
      success:function(res){
        console.log(res);
        that.setData({
          list: res.data.list,
          info: res.data.info,
          five: res.data.five,
          hbinfo:res.data.hbinfo
        })
        console.log(that.data.info)
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})